// 	ID : pallab81
// 	PROG : 11081
// 	LANG : C++
// 	2011-08-21-13.49.52 Sunday
//
// 	"I have not failed, I have just found 10000 ways that won't work.
//


#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>

using namespace std;

#define CI( x ) scanf("%d",&x)
#define CL( x ) scanf("%lld",&x)
#define CD( x ) scanf("%lf",&x )
#define fo(i,ed) for(int i = 0 ; i < ed ; ++i )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define f first
#define s second
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )

char s1[61],s2[61],s3[61];
int l1,l2,l3;
Int cando[61][61][61];
const int mod = 10007;

inline void Read() {
    scanf("%s %s %s",s1,s2,s3);
    l1 = strlen(s1);
    l2 = strlen(s2);
    l3 = strlen(s3);
}

inline int go(int i, int j, int k) {
    if(k==l3) {
        return 1;
    }

    int ways = cando[i][j][k];
    if(ways!=-1) {
        return ways;
    }
    ways=0;
    for(int id=i; id<l1; ++id) {
        if( s3[k]==s1[id] ) {
            ways+= go( id+1, j, k+1 );
        }
    }
    for(int id=j; id<l2; ++id) {
        if( s3[k]==s2[id] ) {
            ways+= go( i, id+1, k+1);
        }
    }

    return cando[i][j][k] = ways%mod;
}
inline void Proc() {
    SET(cando,-1);
    printf("%d\n", (int)go(0,0,0));
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("in.txt","rt",stdin);
#endif

    int cases;
    CI(cases);
    while( cases--  ) {
        Read();
        Proc();
    }
    return 0;
}
